﻿using Microsoft.SharePoint;

namespace SPRepository
{
    public class ItemContentType : BaseContentType, IContentType<ItemContentTypeDto>
    {
        #region FieldTypes

        public static SimpleFieldType<string> Title
        {
            get { return new SimpleFieldType<string>(SPBuiltInFieldId.Title); }
        }

        #endregion

        #region Methods

        public new ItemContentTypeDto Get(object item)
        {
            BaseContentTypeDto baseDto = base.Get(item);

            var spListItem = item as SPListItem;

            var title = Title.GetValue(spListItem);
            var itemContentTypeDto = new ItemContentTypeDto(title, baseDto);

            return itemContentTypeDto;
        }

        public void Update(object item, ItemContentTypeDto dto)
        {
            base.Update(item, dto);

            var spListItem = item as SPListItem;

            Title.SetValue(spListItem, dto.Title);
        }

        #endregion

        #region ContentTypeId

        public override string GetContentTypeIdDefinition()
        {
            return SPBuiltInContentTypeId.Item.ToString();
        }

        #endregion
    }
}